<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../taglib.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>系统模型</title>
<base href="<%=basePath%>" />
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
<script type="text/javascript">
	var treeRoot;
    var searchNode = new Array();
	$(function() {
		<%--tree操作--%>
		$('#tree').tree({
			data : [ {
				id : 'null',
				text : 'ROOT',
				state : 'closed',
				attributes :{type:'all',folder:''}
			} ],
			onClick : function(node) {
				if (node.attributes != undefined) {
					var isLeaf = $('#tree').tree('isLeaf', node.target);
					if(!isLeaf){
						$('#list').attr('src','webviews/model/list.jsp?type='+node.attributes.type+'&folder='+node.attributes.folder);
					}else{
						$('#list').attr('src','webviews/model/view.jsp?type='+node.attributes.type+'&code='+node.id);
					}
				}
			},
			onBeforeLoad : function(node, param) {
				if (node != null) {
					$('#tree').tree('options').url = 'dragon/model/action/ModelHandler/tree2.ejw?type='+node.attributes.type+'&folder='+node.attributes.folder;
				}
				return true;
			}
		});
		treeRoot = $('#tree').tree('getRoot');
		$('#tree').tree('expand', treeRoot.target);
		
		/* $(".panel-tool:first").prepend("<a href=\"javascript:void(0);\" class=\"panel-tool-a icon-search\" title=\"模型检索\" onclick=\"searchModel()\"></a>"); */
		$(".panel-tool:first").prepend("<a href=\"javascript:void(0);\" class=\"panel-tool-a icon-reload\" title=\"重新加载模型\" onclick=\"reloadAll()\"></a>");
	});
	<%--tree操作--%>
	function reloadAll() {
		$.get('dragon/model/action/ModelHandler/reloadAll.ejw', {}, function(data) {
			if (data == 't') {
				$('#tree').tree('reload', treeRoot.target);
			} else {
				top.showErrorMsg('错误', data);
			}
		});
	}
	function reloadSelected() {
		var selected = $('#tree').tree('getSelected');
		if (selected == null) {
			selected = treeRoot;
		}
		$('#tree').tree('reload', selected.target);
	}
	<%--搜索--%>
	function searchModel() {
		top.showPrompt('模型检索', '请输入模型编码或名称！', doSearch);
	}
	function doSearch(v) {
		if (v == null || v == "") {
			return;
		}
		resetICON();
		var children;
		var node = $('#tree').tree('getSelected');
		if (node == null) {
			node = treeRoot;
		}
		children = $('#tree').tree('getChildren', node.target);
		var s = '';
		for ( var i = 0; i < children.length; i++) {
			s += children[i].id + ',' + children[i].text + ',' + $('#tree').tree('isLeaf', children[i].target) + '\n';
			if (($('#tree').tree('isLeaf', children[i].target)) == true) {
				if ((children[i].text.indexOf(v) != -1) || v == children[i].id.substring(children[i].id.indexOf('.') + 1) || v == children[i].id) {
					//编码全匹配(数据模型可不匹配表模式)，名称模糊匹配
					children[i].target.childNodes[3].setAttribute('class', 'tree-icon tree-file icon-ok');
					searchNode.push(children[i]);
					$('#tree').tree('update', children[i]);
					var parent = $('#tree').tree('getParent', children[i].target);
					$('#tree').tree('expand', parent.target);
				}
			}
		}
	}
	<%--图标重置--%>
	function resetICON() {
		var obj = null;
		while ((obj = searchNode.pop()) != null) {
			obj.target.childNodes[3].setAttribute('class', 'tree-icon tree-file');
			$('#tree').tree('update', obj);
			var parent = $('#tree').tree('getParent', obj.target);
			$('#tree').tree('collapse', parent.target);
		}
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'west',split:true" title="模型" style="width: 200px;">
			<ul id="tree"></ul>
		</div>
		<div data-options="region:'center',title:'模型定义'" style="background: #fafafa; overflow: hidden">
			<iframe id="list" style="width: 100%; height: 100%;" frameborder="0" scrolling='yes' src=""></iframe>
		</div>
	</div>
</body>
</html>
